//
//  Emotion.m
//  微博2期
//
//  Created by J on 15/12/13.
//
//

#import "Emotion.h"
#import "MJExtension.h"
@interface Emotion () <NSCoding>

@end

@implementation Emotion



//从文件中解析对象调用
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super init]) {//如果super有 initWithCoder 就直接调用super  initWithCoder没有就直接init
        
        self.chs = [aDecoder decodeObjectForKey:@"chs"];
        self.png = [aDecoder decodeObjectForKey:@"png"];
        self.code = [aDecoder decodeObjectForKey:@"code"];
        
//        [self enumerateIvarsWithBlock:^(MJIvar *ivar, BOOL *stop) {
////         一个 ivar代表一个成员变量
//        ivar.value = [aDecoder decodeObjectForKey:ivar.name];
//        }];

    }
    
    return self;
}

//将对象写入文件
- (void)encodeWithCoder:(NSCoder *)aCoder{
    
    [aCoder encodeObject:self.code forKey:@"code"];
    [aCoder encodeObject:self.png forKey:@"png"];
    [aCoder encodeObject:self.chs forKey:@"chs"];

}


- (BOOL)isEqual:(Emotion*)object{//用来比较两个对象是否是同一个对象
    //    if (self == object) {
    //        return YES;
    //    }else{
    //        return NO;
    //    }
//    NSLog(@"%@ -- %@",self.chs,object.chs);
    NSString* str1 = @"jack";
    NSString* str2 = [NSString stringWithFormat:@"jack"];
    [str1 isEqual:str2];//NO
    [str1 isEqualToString:str2];//YES
//    [self.chs isEqualToString:object.chs];//比的是字符串内容
//    [self.chs isEqual:object.chs];//比的是内存地址
    return [self.chs isEqualToString:object.chs]||[self.code isEqualToString:object.code];
    
}
@end
